function objScoreResults = calcObjectiveScore(dreamPar,parSetVec)
global Extra;




nModelEvals = 0;
objScoreResults  = zeros(size(parSetVec,1),2);

for r = 1:size(parSetVec,1)
    %if ~all(isnan(objScoreResults(r,:))) && ~objScoreResults(r,evalCol)
        % the model has not been evaluated with...
        % the parameters in the current row

        % Set the 'model iteration' number:
        nModelEvals = nModelEvals + 1;
       % objScoreResults(r,iterCol) = nModelEvals;

        % read a line from the matrix containing rows of parameter vectors
       parVec = parSetVec(r,:);

%         if dreamPar.verboseOutput        
%             % update the progress indicator:
%             dispprogress(dreamPar,nModelEvals)
%         end
        %disp(dreamPar.modelCallStr);
        %disp(parVec);
        try
            eval(strcat('cd ', Extra.ModelHome));
            % let the model under consideration run with the selected parameters:
            eval(dreamPar.modelCallStr);

        catch
            
            objScoreResults(r) = NaN;

            warning('DREAM:errorDuringModelEvaluation',...
                    ['An error occurred while evaluati',...
                    'ng the model.'])
            
        end

        
        try

            % compare the model result with the measurements and calculate the...
            % corresponding score according to an objective function:
            eval(dreamPar.objCallStr)

            objScoreResults(r,:) = [objScore, logObjScore];
            eval(strcat('cd ', Extra.DREAMHome));
            
            if isnan(objScore)
                warning('DREAM:objectiveScoreEqualsNaN',...
                    'Objective score is NaN')
            end
            
        catch
            
            objScoreResults(r) = NaN;

            warning('DREAM:errorDuringCallToObjectiveFunction',...
                    ['An error occurred while calculati',...
                    'ng the objective score.'])
            
        end
        
        
               
%         if dreamPar.verboseOutput
%             numDecimals = max(0,ceil(log10(dreamPar.nModelEvalsMax/100)));
%             fprintf(1,repmat('\b',[1,19+...
%                 numDecimals+5+3]))
%         end

    %end
end


% 
% function dispprogress(dreamPar,nModelEvals)
% 
% p = 100*nModelEvals/dreamPar.nModelEvalsMax;
% numDecimals = max(0,ceil(log10(dreamPar.nModelEvalsMax/100)));
% str = sprintf(['DREAM-ua progress : %% %d.%df %%%%',char(10)],numDecimals+5,numDecimals);
% fprintf(1,str,p)
% 
